From fc3f7429f5acade28259a26f7bb81a7a4ca93222 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 22 Oct 2002 18:48:08 +0000 Subject: [PATCH] From Peter Roosen Add -t, -w, -r command lines Activate/fix code in magproto to parse tracks. From me: csv, dna, holux, mxf, ozi, psp, tpg, misc language conformance cleanups. --- csv.c | 2 +- defs.h | 27 +++++++++++++++++++++------ dna.c | 4 ++-- holux.c | 14 +++++--------- magellan.h | 2 ++ magproto.c | 39 ++++++++++++++++++++++++++++----------- main.c | 15 ++++++++++++++- mxf.c | 2 +- ozi.c | 2 +- psp.c | 14 +++++++------- tpg.c | 12 ++++++------ 11 files changed, 88 insertions(+), 45 deletions(-) diff --git a/csv.c b/csv.c index 8f2df9dc9..4e90207e3 100644 --- a/csv.c +++ b/csv.c @@ -85,7 +85,7 @@ data_read(void) do { linecount++; - memset(&buff, '\0', sizeof(buff)); + memset(buff, '\0', sizeof(buff)); fgets(buff, sizeof(buff), file_in); if (strlen(buff)) { diff --git a/defs.h b/defs.h index 88271b8af..b33ac3ff7 100644 --- a/defs.h +++ b/defs.h @@ -30,12 +30,6 @@ * data in this file. */ -typedef struct { - int synthesize_shortnames; - int debug_level; -} global_options; - -extern global_options global_opts; /* * A coordinate in space. @@ -64,6 +58,27 @@ typedef struct { altitude altitude; } position; + +/* + * Define globally on which kind of data gpsbabel is working. + * Important for "file types" that are essentially a communication + * protocol for a receiver, like the Magellan serial data. + */ +typedef enum { + trkdata = 0 , + wptdata, + rtedata +} gpsdata_type; + +typedef struct { + int synthesize_shortnames; + int debug_level; + gpsdata_type objective; +} global_options; + +extern global_options global_opts; + + /* * Extended data if waypoint happens to represent a geocache. This is * totally voluntary data... diff --git a/dna.c b/dna.c index d4116e983..10b0c699e 100644 --- a/dna.c +++ b/dna.c @@ -72,7 +72,7 @@ data_read(void) do { linecount++; - memset(&buff, '\0', sizeof(buff)); + memset(buff, '\0', sizeof(buff)); fgets(buff, sizeof(buff), file_in); if (strlen(buff)) { @@ -87,7 +87,7 @@ data_read(void) while (s) { switch (i) { - case 0: // WPT #, skip. + case 0: /* WPT #, skip. */ break; case 1: wpt_tmp->position.latitude.degrees = atof(s); diff --git a/holux.c b/holux.c index a233f9ba2..04fa7c3a0 100644 --- a/holux.c +++ b/holux.c @@ -85,8 +85,6 @@ static void data_read(void) int iWptNum; int iWptIndex; WPT *pWptHxTmp; - int iWptLen; - DWORD dwIndex; struct tm tm; struct tm *ptm; @@ -101,7 +99,6 @@ static void data_read(void) fatal("GPSBABEL: Error reading data from .wpo file\n"); } - iWptLen = sizeof(WPT); iWptNum = le_read16(&((WPTHDR *)HxWpt)->num); /* Get the waypoints */ @@ -110,7 +107,6 @@ static void data_read(void) wpt_tmp = xcalloc(sizeof(*wpt_tmp), 1); iWptIndex = le_read16(&((WPTHDR *)HxWpt)->idx[iCount]); - dwIndex= OFFS_WPT + (sizeof(WPT) * iWptIndex); pWptHxTmp = (WPT *)&HxWpt[OFFS_WPT + (sizeof(WPT) * iWptIndex)]; wpt_tmp->position.altitude.altitude_meters = 0; @@ -196,15 +192,15 @@ static void holux_disp(const waypoint *wpt) /* set Waypoint */ pWptHxTmp = (WPT *)&HxWFile[OFFS_WPT + (sizeof(WPT) * sIndex)]; - memset (&(pWptHxTmp->name),0x20,sizeof(pWptHxTmp->name)); + memset (pWptHxTmp->name,0x20,sizeof(pWptHxTmp->name)); if (wpt->shortname != NULL) - strncpy((char *)&(pWptHxTmp->name), mknshort(wpt->shortname,sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name)); + strncpy(pWptHxTmp->name, mknshort(wpt->shortname,sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name)); else - sprintf((char *)&(pWptHxTmp->name),"W%d",sIndex); + sprintf(pWptHxTmp->name,"W%d",sIndex); - memset (&(pWptHxTmp->comment),0x20,sizeof(pWptHxTmp->comment)); + memset (pWptHxTmp->comment,0x20,sizeof(pWptHxTmp->comment)); if (wpt->description != NULL) - strncpy((char *)&(pWptHxTmp->comment), mknshort(wpt->description,sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment)); + strncpy(pWptHxTmp->comment, mknshort(wpt->description,sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment)); /*set the time */ if (wpt->creation_time) diff --git a/magellan.h b/magellan.h index 8f4d2c14c..6d401f175 100644 --- a/magellan.h +++ b/magellan.h @@ -45,3 +45,5 @@ typedef struct icon_mapping { const char * mag_find_descr_from_token(const char *token); const char * mag_find_token_from_descr(const char *icon); + +waypoint * mag_trkparse(char *trkmsg); diff --git a/magproto.c b/magproto.c index 83272a2a2..3c88c3f4b 100644 --- a/magproto.c +++ b/magproto.c @@ -37,6 +37,8 @@ HANDLE comport; #define debug_serial (global_opts.debug_level > 1) +extern gpsdata_type objective; + static char * termread(char *ibuf, int size); static void termwrite(char *obuf, int size); @@ -344,9 +346,9 @@ mag_readmsg(void) isump = &ibuf[isz-1]; isum = strtoul(isump, NULL,16); if (isum != mag_pchecksum(&ibuf[1], isz-3)) { -if (debug_serial) - fprintf(stderr, "RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf); - /* Special case receive errors early on. */ + if (debug_serial) + fprintf(stderr, "RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf); + /* Special case receive errors early on. */ if (!got_version) { fatal(MYNAME ": bad communication. Check bit rate.\n"); } @@ -362,6 +364,10 @@ if (debug_serial) waypoint *wpt = mag_wptparse(ibuf); waypt_add(wpt); } + if (strncmp(ibuf, "$PMGNTRK,", 7) == 0) { + waypoint *wpt = mag_trkparse(ibuf); + waypt_add(wpt); + } if (IS_TKN("$PMGNVER,")) { mag_verparse(ibuf); return; @@ -613,7 +619,8 @@ mag_deinit(void) fclose(magfile_in); magfile_in = NULL; } -#if 0 + + /* * Given an incoming track messages of the form: * $PMGNTRK,3605.259,N,08644.389,W,00151,M,201444.61,A,,020302*66 @@ -639,7 +646,7 @@ mag_trkparse(char *trkmsg) sscanf(trkmsg,"$PMGNTRK,%lf,%c,%lf,%c,%d,%c,%d.%d,A,,%d", &latdeg,&latdir, - &lngdeg,&lngsecs,&lngdir, + &lngdeg,&lngdir, &alt,&altunits,&hms,&fracsecs,&dmy); tm.tm_sec = hms % 100; @@ -667,7 +674,8 @@ mag_trkparse(char *trkmsg) return waypt; } -#endif + + const char * mag_find_descr_from_token(const char *token) @@ -773,15 +781,24 @@ mag_wptparse(char *trkmsg) } static void -mag_readwpt(void) +mag_read(void) { if (!is_file) { - mag_writemsg("PMGNCMD,WAYPOINT"); + switch (global_opts.objective) + { + case trkdata: + mag_writemsg("PMGNCMD,TRACK,2"); + break; + case wptdata: + mag_writemsg("PMGNCMD,WAYPOINT"); + break; + default: + fatal(MYNAME ": Routes are not yet supported\n"); + } } - while (!found_done) { + while (!found_done) mag_readmsg(); - } } static @@ -871,6 +888,6 @@ ff_vecs_t mag_vecs = { mag_wr_init, mag_deinit, mag_deinit, - mag_readwpt, + mag_read, mag_write, }; diff --git a/main.c b/main.c index 29701dc27..e0730a34e 100644 --- a/main.c +++ b/main.c @@ -22,10 +22,14 @@ global_options global_opts; +gpsdata_type objective = wptdata; /* if no explicit data type is given, assume waypoints */ + + + void usage(const char *pname) { - printf("Usage: %s [-s] -i -f -o -F \n", pname); + printf("Usage: %s [-s] [-t|-w|-r] -i -f -o -F \n", pname); printf("Supported file types:\n"); disp_vecs(); } @@ -94,6 +98,15 @@ main(int argc, char *argv[]) case 's': global_opts.synthesize_shortnames = 1; break; + case 't': + objective = trkdata; + break; + case 'w': + objective = wptdata; + break; + case 'r': + objective = rtedata; + break; case 'D': global_opts.debug_level = atoi(optarg); argn++; diff --git a/mxf.c b/mxf.c index 412fa69a1..e2e25e148 100644 --- a/mxf.c +++ b/mxf.c @@ -78,7 +78,7 @@ data_read(void) do { linecount++; - memset(&buff, '\0', sizeof(buff)); + memset(buff, '\0', sizeof(buff)); fgets(buff, sizeof(buff), file_in); if (strlen(buff)) { diff --git a/ozi.c b/ozi.c index 0f6ec4612..3ef4ac262 100644 --- a/ozi.c +++ b/ozi.c @@ -77,7 +77,7 @@ data_read(void) do { linecount++; - memset(&buff, '\0', sizeof(buff)); + memset(buff, '\0', sizeof(buff)); fgets(buff, sizeof(buff), file_in); if ((strlen(buff)) && (strstr(buff, ",") != NULL)) { diff --git a/psp.c b/psp.c index 5e4773a80..c8a752751 100644 --- a/psp.c +++ b/psp.c @@ -361,8 +361,8 @@ psp_waypt_pr(const waypoint *wpt) lon = (wpt->position.longitude.degrees * M_PI) / 180.0; /* 4 leading bytes */ - memset(&tbuf, '\0', sizeof(tbuf)); - fwrite(&tbuf, 1, 4, psp_file_out); + memset(tbuf, '\0', sizeof(tbuf)); + fwrite(tbuf, 1, 4, psp_file_out); /* my test files seem to always have this byte as 0x03, */ /* although nothing seems to really care. */ @@ -381,16 +381,16 @@ psp_waypt_pr(const waypoint *wpt) c = 0x14; /* display pin name on! display notes on! */ fwrite(&c, 1, 1, psp_file_out); - memset(&tbuf, '\0', sizeof(tbuf)); + memset(tbuf, '\0', sizeof(tbuf)); /* 3 unknown bytes */ - fwrite(&tbuf, 1, 3, psp_file_out); + fwrite(tbuf, 1, 3, psp_file_out); /* 1 icon byte 0x00 = PIN */ - fwrite(&tbuf, 1, 1, psp_file_out); + fwrite(tbuf, 1, 1, psp_file_out); /* 3 unknown bytes */ - fwrite(&tbuf, 1, 3, psp_file_out); /* 3 junk */ + fwrite(tbuf, 1, 3, psp_file_out); /* 3 junk */ c = strlen(shortname); /* 1 string size */ @@ -448,7 +448,7 @@ psp_write(void) /* insert waypoint count into header */ le_write16(&header_bytes[12], s); - fwrite(&header_bytes, 1, 32, psp_file_out); + fwrite(header_bytes, 1, 32, psp_file_out); waypt_disp_all(psp_waypt_pr); } diff --git a/tpg.c b/tpg.c index 603961ad1..d7dd62c11 100644 --- a/tpg.c +++ b/tpg.c @@ -321,8 +321,8 @@ tpg_waypt_pr(const waypoint *wpt) fwrite(&elev, 1, 2, tpg_file_out); /* 4 unknown bytes */ - memset(&tbuf, '\0', sizeof(tbuf)); - fwrite(&unknown4, 1, 4, tpg_file_out); + memset(tbuf, '\0', sizeof(tbuf)); + fwrite(unknown4, 1, 4, tpg_file_out); /* 1 bytes stringsize for description */ c = strlen(description); @@ -332,7 +332,7 @@ tpg_waypt_pr(const waypoint *wpt) fwrite(description, 1, c, tpg_file_out); /* and finally 2 unknown bytes */ - fwrite(&unknown2, 1, 2, tpg_file_out); + fwrite(unknown2, 1, 2, tpg_file_out); free (shortname); free (description); @@ -359,13 +359,13 @@ tpg_write(void) fatal(MYNAME ": attempt to output too many points (%d). The max is %d. Sorry.\n", s, MAXTPGOUTPUTPINS); } - le_write16(&uc, s); + le_write16(uc, s); /* write the waypoint count */ - fwrite(&uc, 1, 2, tpg_file_out); + fwrite(uc, 1, 2, tpg_file_out); /* write the rest of the header */ - fwrite(&header_bytes, 1, 19, tpg_file_out); + fwrite(header_bytes, 1, 19, tpg_file_out); waypt_disp_all(tpg_waypt_pr); } -- 2.30.2